﻿using System;
using System.ComponentModel.Composition;
using System.Windows.Input;
using IntoNails.Infrastructure;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.ViewModel;

namespace IntoNails.Modules.StartUp.ViewModels
{
    [Export(typeof(IStartUpRibbonTabViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class StartUpRibbonTabViewModel : NotificationObject, IStartUpRibbonTabViewModel
    {
        private readonly IEventAggregator _eventAggregator;
        private readonly IRegionManager _regionManager;

        private bool _isTabSelected;

        [ImportingConstructor]
        public StartUpRibbonTabViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
        {
            this._eventAggregator = eventAggregator;
            this._regionManager = regionManager;
        }

        public string HeaderInfo
        {
            get { return "Start Up"; }
        }

        public bool IsTabSelected
        {
            get { return this._isTabSelected; }
            set
            {
                this._isTabSelected = value;

                if (value)
                {
                    Uri workspaceUri = new Uri("StartUpView", UriKind.Relative);
                    this._regionManager.RequestNavigate(RegionNames.WorkspaceRegion, workspaceUri);
                }

                base.RaisePropertyChanged(() => IsTabSelected);
            }
        }
    }
}
